package com.cos66.store;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.List;

import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

import android.util.Log;

import com.cos66.handler.HotActivityHandler;
import com.cos66.model.HotActivityItem;

public class HotActivityListDataFromXml {
	
	private static final String TAG = "HotActivityListDataFromXml";
	
	private List<HotActivityItem> data = null;
	
	public HotActivityListDataFromXml(File file){
		try {
			InputStream inputStream = new FileInputStream(file);
			initData(inputStream);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			Log.e(TAG, e.toString());
		}
	}
	
	public HotActivityListDataFromXml(InputStream inputStream) {
		initData(inputStream);
	}
	
	public List<HotActivityItem> getData() {
		return data;
	}
	
	private void initData(InputStream inputStream){
		try {
			SAXParserFactory factory = SAXParserFactory.newInstance();
			XMLReader reader = factory.newSAXParser().getXMLReader();
			HotActivityHandler handler = new HotActivityHandler();
			reader.setContentHandler(handler);
			reader.parse(new InputSource(inputStream));
			data = handler.getData();
		} catch (Exception e) {
			System.out.println(e.toString());
			e.printStackTrace();
		}
	}
}
